import { apiSystemMange } from 'js/api'

export default {
  state: {
    departList: [],
    departPar: {
      accessToken: '',
      threeMenuCode: '',
      currentPage: 1,
      showCount: 999
    }
  },
  getters: {
    departList: state => state.departList
  },
  actions: {
    /**
     * 获取部门列表
     */
    fetchDepartList({ state }, param) {
      state.departPar.accessToken = param.token
      state.departPar.threeMenuCode = param.threeMenuCode

      apiSystemMange.getDepartLis(state.departPar).then(data => {
        const list = data.data.recordList || {}
        state.departList = list.map(val => {
          return {
            value: val.id,
            label: val.departmentName
          }
        })
        state.departList.unshift({value: '', label: '请选择'})
      })
    }
  }
}